const app = getApp();
import grace from "../../../utils/grace.js";

grace.page({
  /**
   * 页面的初始数据
   */
  data: {
    student_id: 0,
    card: 0,
    card_code: 0,
    ferry_code_ref: ''
  },
  onLoad(e){
    this.$data.student_id = e.student_id;
    this.$data.card = e.card;
    this.$data.card_code = e.code;
    this.$data.ferry_code_ref = e.ref;
  },
  card_cancel(){
    let that = this;
    wx.showModal({
      title: '提示',
      content: '作废后该卡将无法使用，确定作废吗？',
      success: function (sm) {
        if (sm.confirm) {
          let token = wx.getStorageSync('token');
          wx.showLoading({
            title: '加载中...',
          })
          let url = app.globalData.api + '/api/v1.0/student/ferry/' + that.$data.student_id;
          let params = {
            token: token,
            operate: 'cancel',
            card: that.$data.card
          }
          that.$http.put(url, params).then((res) => {
            if (res.data.code == 0) {
              wx.showToast({
                title: '操作成功！',
                icon: 'success',
                duration: 1000
              })
            }else{
              wx.showModal({
                title: '错误',
                content: res.data.msg,
                showCancel: false
              })
            }
            wx.hideLoading();
          })
        }
      }
    })
  }
})